local ReviveStar = MClass("ReviveStar")

--ctor 初始化UI init设置静态数据 setData设置动态数据  updateData更新数据
function ReviveStar:ctor()
    --self.root 默认为根节点
    self.bg_1 = self:findChild("Panel/bg_1")
    self.bg_2 = self:findChild("Panel/bg_2")
    self.light_1 = self:findChild("Panel/light_1")
    self.light_2 = self:findChild("Panel/light_2")

	self.star = self.bg_1
	self.light = self.light_1

	self.isHiding = false

	self:init()
end

function ReviveStar:init()
	self.light_1:setVisible(false)
	self.light_2:setVisible(false)

	 --ui action
    self:initUIAction()
end

function ReviveStar:initUIAction()
    if self.mAction == nil then
        self.mAction = cc.CSLoader:createTimeline(Res.ReviveStarNode)
        if self.mAction then
            self:runAction(self.mAction)
            self.mAction:gotoFrameAndPause(0)
        end
    end
end

function ReviveStar:setIsSelf(b)
	if b then
		--己方
		self.bg_1:setVisible(true)
		self.bg_2:setVisible(false)
		
		self.star = self.bg_1
		self.light = self.light_1
	else 
		--敌方
		self.bg_1:setVisible(false)
		self.bg_2:setVisible(true)

		self.star = self.bg_2
		self.light = self.light_2
	end
end

function ReviveStar:setData(data)

end

function ReviveStar:updateData(data)
	
end

function ReviveStar:setIsShow(b)
	if b then
		if self.isHiding then
			self.isHiding = false
			if self.mAction then
				self.mAction:clearLastFrameCallFunc()
				self.mAction:gotoFrameAndPause(0)
			end
			self.star:setVisible(true)
			self.light:setVisible(false)
		end
	else
		--如果隐藏
		if not self.isHiding then
			self:playHideAction()
		end
	end
end

function ReviveStar:playHideAction()
	self.isHiding = true
	if self.mAction then
		self.light:setVisible(true)
		self.mAction:clearLastFrameCallFunc()

    	self.mAction:play("animation",false)
    	self.mAction:setLastFrameCallFunc(function()
			self.star:setVisible(false)
			self.light:setVisible(false)
			-- self.isHiding = false
	        self.mAction:clearLastFrameCallFunc()
	    end)
	end
end

return ReviveStar